﻿Imports DTO
Imports System.Data.SqlClient

Public Class CLyDoThanhLyDAO
    Public Function LayDanhSachLyDoThanhLySach() As List(Of CLyDoThanhLyDTO)
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_LayDanhSachLyDoThanhLy", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim listldtl As New List(Of CLyDoThanhLyDTO)()
            Using reader As IDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
                While reader.Read()
                    listldtl.Add(New CLyDoThanhLyDTO(reader))
                End While
            End Using
            Return listldtl
        End Using
    End Function


    Public Function ThemLyDoThanhLy(ByVal tenlydothanhly As String) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_ThemLyDoThanhLy", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@tenlydothanhly", tenlydothanhly)
            cm.Parameters.Add(para)
            Dim parakq As New SqlParameter("@kt", 0)
            parakq.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakq)
            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function


    Public Function CapNhatLyDoThanhLy(ByVal lydothanhly As CLyDoThanhLyDTO) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_CapNhatLyDoThanhLy", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@malydothanhly", lydothanhly.Ma)
            cm.Parameters.Add(para)
            para = New SqlParameter("@tenlydothanhly", lydothanhly.Ten)
            cm.Parameters.Add(para)
            Dim parakt As New SqlParameter("@kt", 0)
            parakt.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakt)

            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function


End Class
